<?php
require 'spl.php';

function valid($p_1, $p_2, $p_3, $p_4) {
    //初始化

    $Parameters = new \liyuze\Parameters\Parameters();
    //配置参数和验证规则
    $Parameters->config([
        'p_1' => [$p_1, 'array'],
        'p_2' => [$p_2, ['array', 'valueValidateConfig' => 'string' ] ],
        'p_3' => [$p_3, ['array', 'keyValidateConfig' => 'string' ] ],
        'p_4' => [$p_4, ['array', 'valueValidateConfig' => ['array', 'valueValidateConfig' => 'integer' ] ] ],
    ], true);

    //验证
    $Parameters->validate();

    return $Parameters->getErrors();
}

function test_pass()
{
    $p_1 = [];
    $p_2 = ['a', 'b', 'c'];
    $p_3 = ['a' => 2, 'b' => 4];
    $p_4 = [[1,2,3], [4,5,6]];
    $r = valid($p_1, $p_2, $p_3, $p_4);
    return json_encode($r, 256);
}


function test_error()
{
    $p_1 = 'array';
    $p_2 = [1,2];
    $p_3 = [2 => 2, 4 => 4];
    $p_4 = [['a', 'b', 'c'], ['a', 'b', 'c']];
    $r = valid($p_1, $p_2, $p_3, $p_4);
    return json_encode($r, 256);
}

var_dump(
    test_pass(),
    test_error()
);

